<template>
  <div class="HuikuiInfo el-card is-always-shadow el-card__body">
    <el-dialog
      title="回馈预览"
      :visible.sync="dialogVisible"
      @close="closed"
      width="950px">
      <avue-crud
        ref="crudOne"
        :option="optionTableOne"
        :data="listTable">
      </avue-crud>
      <avue-crud
        ref="crudTwo"
        :option="optionTable"
        :data="listTableTwo">
        <template slot="menuLeft">
          {{cengjiType.split('-')[1]}}系统数据对比与回馈
        </template>
        <template slot-scope="scope" slot="replySaleMoney">
          <el-input :disabled="showType==2" type="input" size="mini" v-model="replySaleMoney"></el-input>
        </template>
        <template slot-scope="scope" slot="replyRechargeMoney">
          <el-input :disabled="showType==2" type="input" size="mini" v-model="replyRechargeMoney"></el-input>
        </template>
        <template slot-scope="scope" slot="replyErrorReturnMoney">
          <el-input :disabled="showType==2" type="input" size="mini" v-model="replyErrorReturnMoney"></el-input>
        </template>
        <template slot-scope="scope" slot="replyComparativeSaleMoney">
          <el-input :disabled="showType==2" type="input" size="mini" v-model="replyComparativeSaleMoney"></el-input>
        </template>
        <template slot-scope="scope" slot="replyComparativeRechargeMoney">
          <el-input :disabled="showType==2" type="input" size="mini" v-model="replyComparativeRechargeMoney"></el-input>
        </template>
        <template slot-scope="scope" slot="replyComparativeErrorReturnMoney">
          <el-input :disabled="showType==2" type="input" size="mini" v-model="replyComparativeErrorReturnMoney"></el-input>
        </template>
      </avue-crud><br/><br/><br/>
      <avue-form :disabled="isReload" :option="option" v-model="formData" @submit="handleSubmit">
        <template  slot="qfReplyReason" slot-scope="scope">
          <el-select :disabled="showType==2" v-model="qfReplyReason" placeholder="请选择" style="width: 150px">
            <el-option
              v-for="(item,index) in qfReplyReasonList"
              :key="index"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </template>
        <template slot-scope="scope" slot="menuForm" >
          <el-button v-if="showType==1" type="primary" @click="handleSubmit" >确认</el-button>
          <el-button @click="closed" >返回</el-button>
        </template>
      </avue-form>
    </el-dialog>
  </div>
</template>


<script>
  import {getForm, postForm} from '@/api/gen/gen'
  import ExportJsonExcel from "js-export-excel";
  import {
    fenExYuangettoFixed,
    getSysDictItemListToDict,
    getMappingStatus,
    numToTwoPoint, getLineName, getStationName
  } from "../../../api/subwayRat/commonCheck";
  import {updateSwAuTvmCashAmountHierarchyDifferenceToHK} from "../../../api/clarifyManagement/JDZYDLCK";
  import ElInput from "../../../../node_modules/element-ui/packages/input/src/input";
  export default {
    components:{
      ElInput
    },
    data() {
      return {
        qfReplyReason :'',
        cengjiType:'', //层级类型 LC,SC,ACC
        replySaleMoney:0,
        replyRechargeMoney:0,
        replyErrorReturnMoney:0,
        replyComparativeSaleMoney:0,
        replyComparativeRechargeMoney:0,
        replyComparativeErrorReturnMoney:0,
        optionTableOne:{},
        listTable:[],
        listTableTwo:[],
        optionTable:{},
        option:{},
        showType : 0,
        isReload:true,
        dialogVisible:true,
        formData:{},
        qfReplyReasonList:[]
      }
    },
    created() {
      this.getOption();
      getSysDictItemListToDict({"type":"QF_REPLY_REASON"}).then((response)=>{
        this.qfReplyReasonList = response.data.data;
      });
    },
    methods: {
      async handleSubmit(){
        if(''==this.qfReplyReason){
          this.$message.warning("请选择回馈原因后提交！");
          return
        }
        let p = {
          id:this.formData.id,
          payType:this.formData.payType,
          replySaleMoney:this.replySaleMoney*100,
          replyRechargeMoney:this.replyRechargeMoney*100,
          replyErrorReturnMoney:this.replyErrorReturnMoney*100,
          replyComparativeSaleMoney:this.replyComparativeSaleMoney*100,
          replyComparativeRechargeMoney:this.replyComparativeRechargeMoney*100,
          replyComparativeErrorReturnMoney:this.replyComparativeErrorReturnMoney*100,
          qfReplyReason:this.qfReplyReason,
          qfReplyDetail:this.formData.qfReplyDetail
        };
        await updateSwAuTvmCashAmountHierarchyDifferenceToHK(p).then((response)=>{
        });
        this.$message.success('回馈成功');
        this.$parent.getList();
        this.closed();
      },
      recallShow(row){
        this.cengjiType=row.$compareType;
        Object.assign(this.formData,row);
        this.listTable.push(row);
        this.listTableTwo.push(row);
        this.replySaleMoney = fenExYuangettoFixed(row,'replySaleMoney');
        this.replyRechargeMoney = fenExYuangettoFixed(row,'replyRechargeMoney');
        this.replyErrorReturnMoney = fenExYuangettoFixed(row,'replyErrorReturnMoney');
        this.replyComparativeSaleMoney = fenExYuangettoFixed(row,'replyComparativeSaleMoney');
        this.replyComparativeRechargeMoney = fenExYuangettoFixed(row,'replyComparativeRechargeMoney');
        this.replyComparativeErrorReturnMoney = fenExYuangettoFixed(row,'replyComparativeErrorReturnMoney');
        this.qfReplyReason = row.qfReplyReason;
        
        // if(1==row.comparativeType){
        //   this.optionTableOne.column[9].hide = true;
        //   this.optionTableOne.column[10].hide = true;
        //   this.optionTableOne.column[11].hide = true;
        //   this.optionTableOne.column[12].hide = false;
        //   this.optionTableOne.column[13].hide = false;
        //   this.optionTableOne.column[14].hide = false;
        // }else{
        //   this.optionTableOne.column[9].hide = false;
        //   this.optionTableOne.column[10].hide = false;
        //   this.optionTableOne.column[11].hide = false;
        //   this.optionTableOne.column[12].hide = true;
        //   this.optionTableOne.column[13].hide = true;
        //   this.optionTableOne.column[14].hide = true;
        // }
      },
      closed(){
        this.dialogVisible=false;
        this.$parent.isShowDia=false;
      },
      getOption(){
        this.showType = this.$parent.showType;
        if(1 == this.$parent.showType) {
          this.isReload = false;
        }
        this.optionTableOne={
          border: false,
          index: false,
          indexLabel: '序号',
          stripe: false,
          menuAlign: 'center',
          menu: false,
          viewBtn: false,
          editBtn: false,
          emptyBtn:false,
          delBtn: false,
          align: 'center',
          addBtn: false,
          column: [{
            fixed: true,
            label: '主键',
            prop: 'id',
            span: 24,
            type: 'input',
            hide: true
          },{
            label: '差异类型',
            prop: 'comparativeType',
            formatter:function(row, value , label, column){
              return value == 1?'SC-LC':'LC-ACC';
            },
            search: false,
            hide: false,
          },{
            hide: false,
            label: '线路名称',
            prop: 'lineCode',
            type: 'select',
            search: false,
            filterable : true,
            display: true, // 动态显隐控制不能删除
            formatter:function (row,v) {
              return getLineName(v);
            }
          }, {
            hide: false,
            label: '站点名称',
            prop: 'stationCode',
            type: 'select',
            search: false,
            filterable : true,
            display: true,// 动态显隐控制不能删除
            formatter:function (row,v) {
              return getStationName(row.lineCode,v);
            }
          },{
            label: '收入日期',
            prop: 'settleTime',
            type: 'datetime',
            format: 'yyyy-MM-dd',
            valueFormat: 'yyyy-MM-dd',
            search: false
          }, {
            hide: false,
            label: 'TVM编号',
            prop: 'tvmOrder',
          },{
            hide: false,
            label: '支付方式',
            prop: 'payType',
            formatter:function (row,v) {
              return getMappingStatus('xw_pay_type',v);
            }
          },{
            width:120,
            label: 'LC售卖金额',
            prop: 'saleAmount',
            formatter:function (row,value , label, column) {
              return row.payType==1?fenExYuangettoFixed(row,'saleAmount'):fenExYuangettoFixed(row,'saleAmount');
            },
            search: false,
            hide: false,
          },{
            width:120,
            label: 'LC充值金额',
            prop: 'depositAmount',
            formatter:function (row,value , label, column) {
              return row.payType==1?fenExYuangettoFixed(row,'depositAmount'):fenExYuangettoFixed(row,'depositAmount');
            },
            search: false,
            hide: false,
          },{
            width:120,
            label: 'LC退款金额',
            prop: 'errorRefundAmount',
            formatter:function (row,value , label, column) {
              return row.payType==1?fenExYuangettoFixed(row,'errorRefundAmount'):fenExYuangettoFixed(row,'errorRefundAmount');
            },
            search: false,
            hide: false,
          },{
            width:120,
            label: 'ACC售卖金额',
            prop: 'beSaleAmount',
            formatter:function (row,value , label, column) {
              return row.payType==1?fenExYuangettoFixed(row,'beSaleAmount'):fenExYuangettoFixed(row,'beSaleAmount');
            },
            search: false,
            hide: false,
          },{
            width:120,
            label: 'ACC充值金额',
            prop: 'beDepositAmount',
            formatter:function (row,value , label, column) {
              return row.payType==1?fenExYuangettoFixed(row,'beDepositAmount'):fenExYuangettoFixed(row,'beDepositAmount');
            },
            search: false,
            hide: false,
          },  {
            width:120,
            label: 'ACC退款金额',
            prop: 'beErrorRefundAmount',
            formatter:function (row,value , label, column) {
              return row.payType==1?fenExYuangettoFixed(row,'beErrorRefundAmount'):fenExYuangettoFixed(row,'beErrorRefundAmount');
            },
            search: false,
            hide: false,
          }, {
            width:120,
            label: '售卖差异金额',
            prop: 'comparativeSelltkAmount',
            formatter:function (row,value , label, column) {
              let amount;
              // if(row.payType==1){
              //   if(row.compareType==1){
              //     amount = ((row.lcCashSellTicket-row.scCashSellTicket)/100).toFixed(2);
              //   }else{
              //     amount = ((row.accCashSellTicket-row.lcCashSellTicket)/100).toFixed(2);
              //   }
              // }else{
              //   if(row.compareType==1){
              //     amount = ((row.lcElecSellTicket-row.scElecSellTicket)/100).toFixed(2);
              //   }else{
              //     amount = ((row.accElecSellTicket-row.lcElecSellTicket)/100).toFixed(2);
              //   }
              // }
              if(row.payType==1){
                  amount = ((row.saleAmount-row.beSaleAmount)/100).toFixed(2);
              }else{
                  amount = ((row.saleAmount-row.beSaleAmount)/100).toFixed(2);
              }
              amount=Number(amount)?amount:'0.00';
              return amount;
            },
            search: false,
            hide: false,
          },{
            width:120,
            label: '充值差异金额',
            prop: 'comparativeInvestAmount',
            formatter:function (row,value , label, column) {
              let amount;
              // if(row.payType==1){
              //     if(row.compareType==1){
              //         amount = ((row.lcCashRecharge-row.scCashRecharge)/100).toFixed(2);
              //     }else{
              //       amount = ((row.accCashRecharge-row.lcCashRecharge)/100).toFixed(2);
              //     }
              // }else{
              //   if(row.compareType==1){
              //     amount = ((row.lcElecRecharge-row.scElecRecharge)/100).toFixed(2);
              //   }else{
              //     amount = ((row.accElecRecharge-row.lcElecRecharge)/100).toFixed(2);
              //   }
              // }
              if(row.payType==1){
                  amount = ((row.depositAmount-row.beDepositAmount)/100).toFixed(2);
              }else{
                  amount = ((row.depositAmount-row.beDepositAmount)/100).toFixed(2);
              }
              amount=Number(amount)?amount:'0.00';
              return amount;
            },
            search: false,
            hide: false,
          },{
            width:120,
            label: '退款差异金额',
            prop: 'comparativeFaretkAmount',
            formatter:function (row,value , label, column) {
              let amount;
              // if(row.payType==1){
              //   if(row.compareType==1){
              //     amount = ((row.lcCashReturn-row.scCashReturn)/100).toFixed(2);
              //   }else{
              //     amount = ((row.accCashReturn-row.lcCashReturn)/100).toFixed(2);
              //   }
              // }else{
              //   if(row.compareType==1){
              //     amount = ((row.lcElecReturn-row.scElecReturn)/100).toFixed(2);
              //   }else{
              //     amount = ((row.accElecReturn-row.lcElecReturn)/100).toFixed(2);
              //   }
              // }
              if(row.payType==1){
                  amount = ((row.errorRefundAmount-row.beErrorRefundAmount)/100).toFixed(2);
              }else{
                  amount = ((row.errorRefundAmount-row.beErrorRefundAmount)/100).toFixed(2);
              }
              amount=Number(amount)?amount:'0.00';
              return amount;
            },
            search: false,
            hide: false,
          }]
        };
        this.optionTable = {
          border: false,
          index: false,
          indexLabel: '序号',
          stripe: false,
          menuAlign: 'center',
          menu: false,
          viewBtn: false,
          editBtn: false,
          emptyBtn:false,
          delBtn: false,
          align: 'center',
          addBtn: false,
          column: [{
            width:160,
            label: 'LC回馈售卖金额',
            prop: 'replySaleMoney',
            formatter:function (row,value , label, column) {
              return fenExYuangettoFixed(row,'replySaleMoney');
            },
            slot:true,
            search: false,
            hide: false,
          },{
            width:160,
            label: 'LC回馈充值金额',
            prop: 'replyRechargeMoney',
            formatter:function (row,value , label, column) {
              return fenExYuangettoFixed(row,'replyRechargeMoney');
            },
            slot:true,
            search: false,
            hide: false,
          },{
            width:160,
            label: 'LC回馈退款金额',
            prop: 'replyErrorReturnMoney',
            formatter:function (row,value , label, column) {
              return fenExYuangettoFixed(row,'replyErrorReturnMoney');
            },
            slot:true,
            search: false,
            hide: false,
          },{
            width:160,
            label: 'ACC回馈售卖金额',
            prop: 'replyComparativeSaleMoney',
            formatter:function (row,value , label, column) {
              return fenExYuangettoFixed(row,'replyComparativeSaleMoney');
            },
            slot:true,
            search: false,
            hide: false,
          },{
            width:160,
            label: 'ACC回馈充值金额',
            prop: 'replyComparativeRechargeMoney',
            formatter:function (row,value , label, column) {
              return fenExYuangettoFixed(row,'replyComparativeRechargeMoney');
            },
            slot:true,
            search: false,
            hide: false,
          },{
            width:160,
            label: 'ACC回馈退款金额',
            prop: 'replyComparativeErrorReturnMoney',
            formatter:function (row,value , label, column) {
              return fenExYuangettoFixed(row,'replyComparativeErrorReturnMoney');
            },
            slot:true,
            search: false,
            hide: false,
          }]
        };
        this.option={
          submitBtn:false,
          emptyBtn:false,
          group:[{
            icon:'',
            label: '',
            prop: 'group',
            column: [{
              label: '清分人员回馈差异原因',
              prop: 'qfReplyReason',
              formslot : true,
              labelWidth:130
            },{
              label: '清分人员详细描述',
              prop: 'qfReplyDetail',
              type:'textarea',
              labelWidth:130,
              disabled: this.showType==2
            }]
          }]
        }
      }
    },
    mounted() {
    }
  }
</script>
